home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / PredatorPrey / calc_wizard.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-22  |  5.9 KB  |  271 lines  |  [TEXT/KAHL]

  1.  
  2.             /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
  3.             /*                                                               */
  4.             /*                    Prototype HP15C Calculator                */
  5.             /*                    James C. Ullrey                            */
  6.             /*                    INRESCO                                    */
  7.             /*                    © 1990                                    */
  8.             /*                    Version    13.97a                            */
  9.             /*                                                               */
  10.             /*                    WIZARD SEGMENT                               */
  11.             /*                                                               */
  12.             /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
  13.  
  14. /*****************************************************************/
  15. /*  I N C L U D E S
  16. /*****************************************************************/
  17. #ifndef __C14__
  18. #include    "PredatorPrey.h"
  19. #endif
  20.  
  21. #include    "windows.h"
  22. #include    "calc_wizard.h"
  23. #include     "Globals.h"
  24. #ifndef __C14D__
  25. #include     "PredatorPreyData.h"
  26. #endif
  27. #ifndef __RED__
  28. #include     "ResourceDefs.h"
  29. #endif
  30. #include     "Miscellany.h"
  31. #include     "Dispatcher.h"
  32. #include    "MainWindow.h"
  33.  
  34.  
  35. #define dialogTop        75
  36. #define dialogLeft        85
  37.  
  38. /********************************************************************/
  39. /*  G L O B A L   V A R I A B L E   D E C L A R A T I O N S*/
  40. /********************************************************************/
  41.  
  42.  
  43. extern    Boolean        gLoadProgEnabled;
  44.  
  45. short            numOpenTypes;
  46. SFTypeList        openPTypeList;
  47. SFTypeList        openDTypeList;
  48. SFTypeList        openBTypeList;
  49.  
  50. extern    void    DoShowWindow(void);
  51.  
  52. static void        DoNew (void);
  53. static void        DoOpen (void);
  54. static void        DoSaveDataAs (void);
  55. static void        DoSaveProgAs (void);
  56. static void        DoSaveData (void);
  57. static void        DoSaveProg (void);
  58.  
  59. void    wizard_seg() {}        /*  for reference in "UnloadSeg()" calls    */
  60.  
  61.  
  62. /*----------*/
  63. void InitFileMD (void)
  64. {
  65.     numOpenTypes = 1;
  66.     openDTypeList [0] = lFileType;
  67. } /*InitFileM*/
  68.  
  69. /*----------*/
  70. void InitFileMP (void)
  71. {
  72.     numOpenTypes = 1;
  73.     openPTypeList [0] = kFileType;
  74. } /*InitFileM*/
  75.  
  76. /*----------*/
  77. void InitFileMB (void)
  78. {
  79.     numOpenTypes = 1;
  80.     openBTypeList [0] = mFileType;
  81. } /*InitFileM*/
  82.  
  83.  
  84. /*----------*/
  85. static void DoNew (void)
  86. {
  87.     /*OpenWindows ("\p", 0, 0);*/
  88.     InitAppData ();                    /* apparently does nothing */
  89.  
  90. } /*DoNew*/
  91.  
  92.  
  93. /*----------*/
  94. static void DoOpenData (void)
  95. {
  96.     Point            dialogOrigin;
  97.     SFReply            sfInfo;
  98.  
  99.     SetPt (&dialogOrigin, dialogLeft, dialogTop);
  100.     SFGetFile (dialogOrigin, "\p", nil, numOpenTypes, openDTypeList, nil, &sfInfo);
  101.     if (sfInfo.good) {
  102.         OpenDoc (sfInfo.fName, sfInfo.vRefNum);        /*    this    */
  103.     }
  104. } /*DoOpen*/
  105.  
  106.  
  107. /*----------*/
  108. static void DoOpenProg (void)
  109. {
  110.     Point            dialogOrigin;
  111.     SFReply            sfInfo;
  112.  
  113.     SetPt (&dialogOrigin, dialogLeft, dialogTop);
  114.     SFGetFile (dialogOrigin, "\p", nil, numOpenTypes, openPTypeList, nil, &sfInfo);
  115.     if (sfInfo.good) {
  116.         OpenDoc (sfInfo.fName, sfInfo.vRefNum);
  117.     }
  118. } /*DoOpen*/
  119.  
  120. /*----------*/
  121. void OpenApp (void)
  122. {
  123.     DoNew ();
  124. } /*OpenApp*/
  125.  
  126.  
  127.  
  128. /*----------*/
  129. static void DoSaveProg (void)
  130. {
  131.     SFReply            sfInfo;
  132.     short            pRefNum;
  133.     short            selector = 1;    /* 1 for program, 0 for data */
  134.     StringHandle    prompt;
  135.     Str255            promptStr;
  136.     Str255            suggestion;
  137.  
  138.     prompt = GetString (SaveProgramAsPromptID);
  139.     
  140.     /* prompt becomes string in dialog box above field for program name */
  141.     
  142.     if (prompt != nil) {
  143.         BlockMove (&(**prompt), promptStr, GetHandleSize ((Handle) prompt));
  144.     } else {
  145.         promptStr [0] = 0;
  146.     }
  147.     BlockMove (&(**cur->pFilename), suggestion, GetHandleSize ((Handle) cur->pFilename));
  148.  
  149.     if (CreateFile (&sfInfo, promptStr, suggestion, kSignature, kFileType)) {
  150.         CloseAppFile (cur->pFileNum);
  151.         if (OpenAppFile (sfInfo.vRefNum, sfInfo.fName, &pRefNum)) {
  152.             /*SetWTitle (curWindow, sfInfo.fName);*/
  153.             cur->pFileNum = pRefNum;
  154.             cur->volNum = sfInfo.vRefNum;
  155.             SetString (cur->pFilename, sfInfo.fName);
  156.             WriteAppFile (selector,cur->pFileNum);     /* in C14CalculatorData.c, does FlushVol() */
  157.             cur->pDirty = false;                    /* doesn't Close()    */
  158.         } else { /*should never happen*/
  159.             /*SetWTitle (curWindow, "\p???");*/
  160.             cur->pFileNum = 0;
  161.             cur->volNum = 0;
  162.         }
  163.     }
  164. } /*DoSaveProg*/
  165.  
  166.  
  167. /*----------*/
  168. static void DoSaveData (void)
  169. {
  170.     SFReply            sfInfo;
  171.     short            qRefNum;
  172.     short            selector = 0;    /* 0 for data, 1 for program */
  173.     StringHandle    prompt;
  174.     Str255            promptStr;
  175.     Str255            suggestion;
  176.  
  177.     prompt = GetString (SaveDataAsPromptID);
  178.     if (prompt != nil) {
  179.         BlockMove (&(**prompt), promptStr, GetHandleSize ((Handle) prompt));
  180.     } else {
  181.         promptStr [0] = 0;
  182.     }
  183.     BlockMove (&(**cur->qFilename), suggestion, GetHandleSize ((Handle) cur->qFilename));
  184.     
  185.     /* cur->qFilename established in WindowInit() in calc_inits.c */
  186.     /* suggestion is default filename to be displayed in input box */
  187.  
  188.     if (CreateFile (&sfInfo, promptStr, suggestion, kSignature, lFileType)) {
  189.         CloseAppFile (cur->qFileNum);
  190.         if (OpenAppFile (sfInfo.vRefNum, sfInfo.fName, &qRefNum)) {
  191.             /*SetWTitle (curWindow, sfInfo.fName);*/
  192.             cur->qFileNum = qRefNum;
  193.             cur->volNum = sfInfo.vRefNum;
  194.             SetString (cur->qFilename, sfInfo.fName);
  195.             WriteAppFile (selector,cur->qFileNum);
  196.             cur->qDirty = false;
  197.         } else { /*should never happen*/
  198.             /*SetWTitle (curWindow, "\p???");*/
  199.             cur->qFileNum = 0;
  200.             cur->volNum = 0;
  201.         }
  202.     }
  203. } /*DoSaveData*/
  204.  
  205.  
  206. /*----------*/
  207. void OpenDoc    (Str255        fileName,
  208.                  short        vRefNum)
  209. {
  210. /* This *should* be defined in an Apple interface file: */
  211. #define StationeryFlag    0x0800
  212.  
  213.     Boolean            isStationery;
  214.     FInfo            finderInfo;
  215.     short            fRefNum;
  216.  
  217.     isStationery = false;
  218.     if (GetFInfo (fileName, vRefNum, &finderInfo) == noErr) {
  219.         if ((finderInfo.fdFlags & StationeryFlag) != 0) {
  220.             isStationery = true;
  221.         }
  222.     }
  223.     if (OpenAppFile (vRefNum, fileName, &fRefNum)) {
  224.         if (isStationery) {
  225.             /*OpenWindows ("\p", 0, 0);*/
  226.             ReadAppFile (fRefNum);
  227.             CloseAppFile (fRefNum);
  228.         } else {
  229.             /*OpenWindows (fileName, vRefNum, fRefNum);*/
  230.             ReadAppFile (fRefNum);        /*    C14CalculatorData.c    */
  231.         }
  232.     }
  233. } /*OpenDoc*/
  234.  
  235. void    DoWizOpenProg    (void)
  236. {
  237.     DoOpenProg();
  238. }
  239.  
  240. void    DoWizOpenData    (void)
  241. {
  242.     DoOpenData();
  243. }
  244.  
  245.  
  246.  
  247.  
  248.  
  249. void    DoWizNew    (void)
  250. {
  251.     DoNew();
  252. }
  253.  
  254. void    DoWizClose    (void)
  255. {
  256.     DoSaveProg();
  257.     FSClose(cur->pFileNum);
  258.     gLoadProgEnabled = TRUE;
  259.     DisableItem(GetMHandle(FILE_MENU_ID), 5);
  260.     EnableItem(GetMHandle(FILE_MENU_ID), 6);
  261. }
  262.  
  263. void    DoWizSaveData(void)
  264. {
  265.     DoSaveData();
  266. }
  267.  
  268. void    DoWizSaveProg(void)
  269. {
  270.     DoSaveProg();
  271. }